package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.ProductDetail;
import cn.gson.springboot.model.pojos.Quotation;
import cn.gson.springboot.model.service.ProductDetailService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ProductDetailController {
    @Autowired
    ProductDetailService proDetailService;

    //根据报价单Id查询详单
    @RequestMapping("/quo-detail-list")
    @ResponseBody
    public List<ProductDetail> quoDetailList(Integer quoId) {
        List<ProductDetail>  productDetails = proDetailService.selectProDetailsByQuoId(quoId);
        return productDetails;
    }

    //根据合同订单Id查询详单
    @RequestMapping("/con-detail-list")
    @ResponseBody
    public List<ProductDetail> conDetailList(Integer conId) {
        List<ProductDetail>  productDetails = proDetailService.selectProDetailsByConId(conId);
        return productDetails;
    }

    //根据采购单Id查询详单
    @RequestMapping("/pur-detail-list")
    @ResponseBody
    public List<ProductDetail> purDetailList(Integer purId) {
        List<ProductDetail>  productDetails = proDetailService.selectProDetailsByPurId(purId);
        return productDetails;
    }

    //查询所有采购详单
    @RequestMapping("/pur-detail-all-list")
    @ResponseBody
    public Map<String,Object> purDetailList(Integer page,Integer size,Integer value,Integer num,String proName) {
        Page<Object> obj = PageHelper.startPage(page, size);
        List<ProductDetail> pro = proDetailService.selectPurProDetails(value,num,proName);
        Map<String,Object> map = new HashMap<>();
        map.put("rows",pro);
        map.put("total",obj.getTotal());
        return map;
    }
}
